package com.leetcode;

/**
 * 26. 删除有序数组中的重复项
 *
 * @author fy
 * @date 2022/4/1 21:41
 */
public class Solution26 {

    public int removeDuplicates(int[] nums) {
        int n = nums.length;
        int cur = nums[0];
        int j = 1;
        for (int i = 1; i < n; i++) {
            if (nums[i] != cur) {
                cur = nums[i];
                nums[j++] = nums[i];
            }
        }
        return j;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{0, 0, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 5};
        new Solution26().removeDuplicates(nums);

        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i] + " ");
        }
    }

}
